/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Oct 14, 2013  11:41:01 AM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.registered
 * File Name : RegisterClasss.java
 * TODO
 */
package com.tis.registered;

import java.io.FileOutputStream;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import com.sap.conn.jco.ext.Environment;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Oct 14, 2013 : 11:41:01 AM 
 * CreateBy=Chatree Siangklom
 * 
 * RegisterClasss
 * TODO
 */
public class RegisterClasss {

	/**
	 * Date =Oct 14, 2013 : 11:41:01 AM 
	 * CreateBy=Chatree Siangklom
	 * RegisterClasss
	 * TODO
	 */
	public RegisterClasss() {
		// TODO Auto-generated constructor stub
	}
	
	public void ShowProperty()  throws Exception {
		Properties prop = new Properties();
		 
    	try {
    		String propFileName = "config.properties";
    		//System.out.println(RegisterClasss.class.getClassLoader().getResourceAsStream("config.properties"));
    		
    		InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
            prop.load(inputStream);
            if (inputStream == null) {
                throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
            }
            
            //load a properties file from class path, inside static method
    		//prop.load(RegisterClasss.class.getClassLoader().getResourceAsStream("config.properties"));
    		
   
 
               //get the property value and print it out
            System.out.println(prop.getProperty("database"));
    		System.out.println(prop.getProperty("dbuser"));
    		System.out.println(prop.getProperty("dbpassword"));
 
    	} catch (IOException ex) {
    		ex.printStackTrace();
        }
	}
	
	public static void main(String [] args) {
		try{
			
			Properties prop = new Properties();
			prop.setProperty("database", "localhost");
    		prop.setProperty("dbuser", "sss");
    		prop.setProperty("dbpassword", "password");
 
    		//save properties to project root folder
    		prop.store(new FileOutputStream("config.properties"), null);
			
    		new RegisterClasss().ShowProperty();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
